﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml;

namespace print
{
    class Config
    {
        private string name;
        private string pageType;
        private int pageWidth;
        private int pageHeight;
        private double itemWidth;
        private double itemHeight;
        private double row;
        private double col;
        private double left;
        private double top;
        private double right;
        private double bottom;
        private bool isTransverse;
        private string groupBy;
        private int start;
        private string sortBy;
        private string sortD;


        private Dictionary<string, SettingItem> settings;
        private XmlDocument xdc = new XmlDocument();

        private List<SettingItem> items;
        private Dictionary<string, Dictionary<string, SettingItem>> settingTable;
        XmlNode xn;
        public Config(string name)
        {
            int out_i = 0;
            xdc.Load("config/setting.xml");
            xn = xdc.SelectSingleNode("config/setting[@name='" + name + "']");
            name = xn.Attributes["name"].Value;
            pageWidth = int.Parse(xn.Attributes["pageWidth"].Value);
            pageHeight = int.Parse(xn.Attributes["pageHeight"].Value);
            itemWidth = int.Parse(xn.Attributes["itemWidth"].Value);
            itemHeight = int.Parse(xn.Attributes["itemHeight"].Value);
            //row = int.Parse(xn.Attributes["row"].Value);
            //col = int.Parse(xn.Attributes["col"].Value);
            if (xn.Attributes["left"] != null && xn.Attributes["left"].Value != "")
                left = int.Parse(xn.Attributes["left"].Value);
            if (xn.Attributes["top"] != null && xn.Attributes["top"].Value != "")
                top = int.Parse(xn.Attributes["top"].Value);
            if (xn.Attributes["right"] != null && xn.Attributes["right"].Value != "")
                right = int.Parse(xn.Attributes["right"].Value);
            if (xn.Attributes["bottom"] != null && xn.Attributes["bottom"].Value != "")
                bottom = int.Parse(xn.Attributes["bottom"].Value);
            if (xn.Attributes["isTransverse"] != null)
                isTransverse = bool.Parse(xn.Attributes["isTransverse"].Value);
            if (xn.Attributes["pagetype"] != null)
                pageType = xn.Attributes["pagetype"].Value;
            if (xn.Attributes["groupBy"] != null)
                groupBy = xn.Attributes["groupBy"].Value;
            if (xn.Attributes["start"] != null && int.TryParse(xn.Attributes["start"].Value, out out_i))
                start = out_i;
            if (xn.Attributes["sortBy"] != null)
                sortBy = xn.Attributes["sortBy"].Value;
            if (xn.Attributes["sortD"] != null)
                SortD = xn.Attributes["sortD"].Value;


            getItemd();
            // getItemTable();
        }
        public string Name { get => name; set => name = value; }
        public int PageWidth { get => pageWidth; set => pageWidth = value; }
        public int PageHeight { get => pageHeight; set => pageHeight = value; }
        public double ItemWidth { get => itemWidth; set => itemWidth = value; }
        public double ItemHeight { get => itemHeight; set => itemHeight = value; }
        public double Row { get => row; set => row = value; }
        public double Col { get => col; set => col = value; }

        public Dictionary<string, SettingItem> Settings { get => settings; set => settings = value; }
        public Dictionary<string, Dictionary<string, SettingItem>> SettingTable { get => settingTable; set => settingTable = value; }
        public double Left { get => left; set => left = value; }
        public double Top { get => top; set => top = value; }
        public bool IsTransverse { get => isTransverse; set => isTransverse = value; }
        public string PageType { get => pageType; set => pageType = value; }
        public string GroupBy { get => groupBy; set { groupBy = value; setAttr("groupBy", value); } }

        public int Start { get => start; set { start = value; setAttr("start", value); } }
        public string SortBy { get => sortBy; set { sortBy = value;; setAttr("sortBy", value); } }
        public string SortD { get => sortD; set => sortD = value; }
        public double Right { get => right; set { right = value; ; setAttr("right", value); } }
    public double Bottom { get => bottom; set { bottom = value; ; setAttr("bottom", value); } }

        // internal List<SettingItem> Items { get => getItems(); set { items = value; getItemd();getItemTable(); } }
        private void setAttr(string name, object val)
        {
            if (xn.SelectSingleNode("@" + name) != null)
            {
                xn.Attributes[name].Value = val.ToString();
            }
            else
            {
                // 创建节点
                XmlNode attr = xn.OwnerDocument.CreateNode(XmlNodeType.Attribute, name, null);
                attr.Value = val.ToString();
                // 添加节点属性
                xn.Attributes.SetNamedItem(attr);
            }
        }

        public List<SettingItem> getItems()
        {
            List<SettingItem> list = new List<SettingItem>();
            XmlNodeList xnl = xn.SelectNodes("item");
            if (xnl != null && xnl.Count > 0)
            {
                for(int i = 0; i < xnl.Count; i++)
                {
                    XmlNode item = xnl[i];
                    list.Add(new SettingItem(item));
                }
            }

            return list;

        }
        public void getItemd()
        {
            Dictionary<string,SettingItem> list = new Dictionary<string, SettingItem>();
            XmlNodeList xnl = xn.SelectNodes("item");
            if (xnl != null && xnl.Count > 0)
            {
                for (int i = 0; i < xnl.Count; i++)
                {
                    XmlNode item = xnl[i];
                    SettingItem setting = new SettingItem(item);

                    if (!list.ContainsKey(setting.Name+setting.Label)) { 
                    list.Add(setting.Name + setting.Label, setting);
                    }
                }
            }

            settings= list;

        }


        public void save()
        {

            xn.Attributes["pageWidth"].Value = pageWidth.ToString();
            xn.Attributes["pageHeight"].Value = pageHeight.ToString();
            xn.Attributes["itemWidth"].Value = itemWidth.ToString();
            xn.Attributes["itemHeight"].Value = itemHeight.ToString();
            if (xn.Attributes["top"] != null) { 
            xn.Attributes["top"].Value = top!=0? top.ToString():"";
            }
            if (xn.Attributes["left"] != null)
                xn.Attributes["left"].Value =left != 0 ? left.ToString() : "";
              
          // xn.Attributes["isTransverse"].Value = IsTransverse.ToString();
            setAttr("isTransverse", IsTransverse.ToString());

            
            xdc.Save("config/setting.xml");
        }
    }



    public class SettingItem
    {
        private string name;
        private string fontSize;
        private string fontFamly;
        private bool black;
        private bool qiandao;
        private string rowNum;
        private string colNum;
        private string align;
        private string label;
        private string split;

        private float width;
        private float height;
        private float left;
        private float top;
        private bool isHide;
        private string itemContent;

        private Color color=Color.Black;
        private List<SettingItem> content=new List<SettingItem>();
        private Dictionary<string,string> map;

        XmlNode xn;
        public SettingItem(XmlNode node)
        {
            xn = node;
            if (xn.Attributes["name"] != null)
            {
                name = xn.Attributes["name"].Value;
            }
            if (xn.Attributes["fontSize"] != null)
            {
                fontSize = xn.Attributes["fontSize"].Value;
            }
            if (xn.Attributes["fontFamly"] != null)
            {
                fontFamly = xn.Attributes["fontFamly"].Value;
            }
            if (xn.Attributes["black"] != null)
            {
                black = bool.Parse(xn.Attributes["black"].Value);
            }
            if (xn.Attributes["qiandao"] != null)
            {
                qiandao = bool.Parse(xn.Attributes["qiandao"].Value);
            }

            if (xn.Attributes["align"] != null)
            {
                align = xn.Attributes["align"].Value;
            }
            if (xn.Attributes["label"] != null)
                label = xn.Attributes["label"].Value;
            if (xn.Attributes["width"] != null)
                width = float.Parse(xn.Attributes["width"].Value);
            if (xn.Attributes["height"] != null)
                height = float.Parse(xn.Attributes["height"].Value);
            if (xn.Attributes["left"] != null)
                left = float.Parse(xn.Attributes["left"].Value);
            if (xn.Attributes["top"] != null)
                top = float.Parse(xn.Attributes["top"].Value);
            if (xn.Attributes["split"] != null)
                split = xn.Attributes["split"].Value;
            if (xn.Attributes["itemContent"] != null)
                itemContent = xn.Attributes["itemContent"].Value;
            if (xn.Attributes["isHide"] != null)
                isHide =bool.Parse( xn.Attributes["isHide"].Value);
            if (xn.Attributes["color"] != null)
                color = System.Drawing.ColorTranslator.FromHtml(xn.Attributes["color"].Value);



            if (xn.Attributes["map"] != null)
            {
                string[] maps = xn.Attributes["map"].Value.Split(';', ',');
                Dictionary<string,string> hs = new Dictionary<string, string>();
                    for (int i = 0; i < maps.Length; i++)
                {
                    string[] hss = maps[i].Split('=');
                    hs.Add(hss[0], hss[1]);
                }
                map = hs;
            }
            if (xn.HasChildNodes)
            {
                for (int i = 0; i < xn.ChildNodes.Count; i++)
                {
                    content.Add(new SettingItem(xn.ChildNodes[i]));
                }
                
            }
        }
        public string Name { get => name; set => name = value; }
        public string Label { get => label; set => label = xn.Attributes ["label"].Value = value; }
        public string FontSize { get => fontSize; set => fontSize = xn.Attributes["fontSize"].Value = value; }
        public string FontFamly { get => fontFamly; set => fontFamly = xn.Attributes["fontFamly"].Value = value; }
        public bool Black{get => black; set {  black = value; setAttr("black", value);  }}
        public bool Qiandao {get => qiandao; set{ qiandao = value; setAttr("qiandao", value);  }}
        public string RowNum { get => rowNum; set => rowNum = xn.Attributes["rowNum"].Value = value; }
        public string ColNum { get => colNum; set => colNum = xn.Attributes["colNum"].Value = value; }
        public string Align { get => align; set => align = xn.Attributes["align"].Value = value; }
        public float Width { get => width; set { width = value;if (xn.SelectSingleNode("@width") != null)
                {
                    xn.Attributes["width"].Value = value.ToString();
                }
                else
                {
                    // 创建节点
                    XmlNode attr = xn.OwnerDocument.CreateNode(XmlNodeType.Attribute, "width", null);
                    attr.Value = value.ToString();
                    // 添加节点属性
                    xn.Attributes.SetNamedItem(attr);
                }
            }
        }
        public float Height { get => height; set { height = value; setAttr("height", value); } }
        public float Left { get => left; set { left =  value; setAttr("left", value); } }
        public float Top { get => top; set { top = value; setAttr("top", value); } }

        public List<SettingItem> Content { get => content; set => content = value; }
        public Dictionary<string, string> Map { get => map; set => map = value; }
        public string Split { get => split; set  { split = value; setAttr("split", value); } }

        public bool IsHide
        {
            get => isHide; set
            {
                
                isHide = value;

                setAttr("isHide", value);
            }
        }

        public string ItemContent { get => itemContent; set { itemContent = value; setAttr("itemContent", value); } }

        public Color Color { get => color; set { color = value;
                setAttr("color", System.Drawing.ColorTranslator.ToHtml(value));
            }
        }

        private void setAttr(string name, object val)
        {
            if (xn.SelectSingleNode("@"+ name) != null)
            {
                xn.Attributes[name].Value = val.ToString();
            }
            else
            {
                // 创建节点
                XmlNode attr = xn.OwnerDocument.CreateNode(XmlNodeType.Attribute, name, null);
                attr.Value = val.ToString();
                // 添加节点属性
                xn.Attributes.SetNamedItem(attr);
            }
        }

        public string getValueByKey(string key)
        {
            if (xn.Attributes[key] !=null)
            {
             return   xn.Attributes[key].Value;
            }
            else
            {
                return "";
            }
        }

        public string getContentByKey(string key)
        {
            if (xn.Attributes[key] != null)
            {
                return xn.Attributes[key].Value;
            }
            else
            {
                return "";
            }
        }
    }

    class ConfigCard:CardItem
    {
        private XmlDocument xdc = new XmlDocument();
        

        private int pageWidth;
        private int pageHeight;
        private double itemWidth;
        private double itemHeight;
        private int top;
        private int bottom;
        private int left;
        private int right;
        XmlNode xn;
        public ConfigCard()
        {
            xdc.Load("config/setting.xml");
            xn = xdc.SelectSingleNode("config/setting[@name='card']");
            initAttr(xn);

            pageWidth = int.Parse(xn.Attributes["pageWidth"].Value);
            pageHeight = int.Parse(xn.Attributes["pageHeight"].Value);
            itemWidth = int.Parse(xn.Attributes["itemWidth"].Value);
            itemHeight = int.Parse(xn.Attributes["itemHeight"].Value);

            if (xn.Attributes["left"] != null && xn.Attributes["left"].Value != "")
                Left1 = int.Parse(xn.Attributes["left"].Value);
            if (xn.Attributes["top"] != null && xn.Attributes["top"].Value != "")
                Top1 = int.Parse(xn.Attributes["top"].Value);

            if (xn.Attributes["right"] != null && xn.Attributes["right"].Value != "")
                Right = int.Parse(xn.Attributes["right"].Value);
            if (xn.Attributes["bottom"] != null && xn.Attributes["bottom"].Value != "")
                Bottom = int.Parse(xn.Attributes["bottom"].Value);
        }

        public int PageWidth { get => pageWidth; set => pageWidth = value; }
        public int PageHeight { get => pageHeight; set => pageHeight = value; }
        public double ItemWidth { get => itemWidth; set => itemWidth = value; }
        public double ItemHeight { get => itemHeight; set => itemHeight = value; }
        public int Top1 { get => top; set => top = value; }
        public int Bottom { get => bottom; set => bottom = value; }
        public int Left1 { get => left; set => left = value; }
        public int Right { get => right; set => right = value; }
    }

  
    class CardList:List<CardP> {

        public CardList(XmlNode xn)
        {
            XmlNodeList xnl = xn.SelectNodes("p");
            if (xnl != null && xnl.Count > 0)
            {
                for (int i = 0; i < xnl.Count; i++)
                {
                    XmlNode item = xnl[i];
                    this.Add(new CardP(item));
                }
            }
        }
    }
    class CardP:List<SettingItem> {
        public CardP(XmlNode xn)
        {
            XmlNodeList xnl = xn.SelectNodes("item");
            if (xnl != null && xnl.Count > 0)
            {
                for (int i = 0; i < xnl.Count; i++)
                {
                    XmlNode item = xnl[i];
                    this.Add(new SettingItem(item));
                }
            }
        }
    }
    public class LabelList : List<LabelItem>
    {
        XmlDocument xdc=new XmlDocument();
        List<LabelItem> list = new List<LabelItem>();
      public LabelList(string xmlFile)
        {
            xdc.Load(xmlFile);
            list = initData();
        }
        public LabelList(XmlDocument xml)
        {
            xdc = xml;
            list = initData();
        }

        internal List<LabelItem> List { get => list; set => list = value; }

        private List<LabelItem> initData()
        {
         XmlNodeList xnl=   xdc.SelectNodes("//datafield[@tag='905']");
            List<LabelItem> list = new List<LabelItem>();
            if (xnl != null && xnl.Count > 0)
            {
                for (int i = 0; i < xnl.Count; i++)
                {
                    XmlNode item = xnl[i];
                    LabelItem p = new LabelItem(item);
                    list.Add(p);
                }
            }

            return list;

        }
       
    }

  public  class LabelItem
    {
        
        XmlNode xn;
        public LabelItem(XmlNode node)
        {
            xn = node;
        }
       public string getKey(string key)
        {
            if (xn.SelectSingleNode("subfield[@code='"+key.Trim()+"']") != null){
                return xn.SelectSingleNode("subfield[@code='" + key.Trim() + "']").InnerText;
            }
            else
            {
                return "";
            }
        }

       
    }


    public class PatronList : List<Patron>
    {
        XmlDocument xdc = new XmlDocument();
        List<Patron> list = new List<Patron>();
        public PatronList(string xmlFile)
        {
            xdc.Load(xmlFile);
            list = initData();
        }
        public PatronList(XmlDocument xml)
        {
            xdc = xml;
            list = initData();
        }

        internal List<Patron> List { get => list; set => list = value; }

        private List<Patron> initData()
        {
            XmlNodeList xnl = xdc.SelectNodes("PATRONLIST/PATRON");
            List<Patron> list = new List<Patron>();
            if (xnl != null && xnl.Count > 0)
            {
                for (int i = 0; i < xnl.Count; i++)
                {
                    XmlNode item = xnl[i];
                    Patron p = new Patron(item);
                    list.Add(p);
                }
            }

            return list;

        }

    }

    public class Patron
    {
        private string flullName;
        private string gender;
        private string barcode;
        private string idcardno;
        private string department;
        private string title;
        private string category;
        private string expiresdate;
        XmlNode xn;
        public Patron(XmlNode node)
        {
            xn = node;
            flullName = xn.Attributes["FULLNAME"].Value;
            gender = xn.Attributes["GENDER"].Value;
            barcode = xn.Attributes["BARCODE"].Value;
            idcardno = xn.Attributes["IDCARDNO"].Value;
            department = xn.Attributes["DEPARTMENT"].Value;
            title = xn.Attributes["TITLE"].Value;
            category = xn.Attributes["CATEGORY"].Value;
            expiresdate = xn.Attributes["EXPIRESDATE"].Value;
        }
        public string getKey(string key)
        {
            if (xn.Attributes[key.Trim()] != null)
            {
                return xn.Attributes[key.Trim()].Value;
            }
            else
            {
                return "";
            }
        }

        public string FlullName { get => flullName; set => flullName = value; }
        public string Gender { get => gender; set => gender = value; }
        public string Barcode { get => barcode; set => barcode = value; }
        public string Idcardno { get => idcardno; set => idcardno = value; }
        public string Department { get => department; set => department = value; }
        public string Title { get => title; set => title = value; }
        public string Category { get => category; set => category = value; }
        public string Expiresdate { get => expiresdate; set => expiresdate = value; }
    }


    public class Record
    {
        private Dictionary<string, string> controlfield=new Dictionary<string, string>();
        private Dictionary<string, object> datafield=new Dictionary<string, object>();

        private XmlDocument xdc = new XmlDocument();
        public Record(string path)
        {
            xdc.Load(path);
            XmlNodeList cons = xdc.SelectNodes("record/controlfield");
            if (cons != null && cons.Count > 0)
            {
                for(int i = 0; i < cons.Count; i++)
                {
                    XmlNode xn = cons.Item(i);
                    if (xn.Attributes["tag"] != null)
                        controlfield.Add(xn.Attributes["tag"].Value, xn.InnerText);
                }
            }
            XmlNodeList datas = xdc.SelectNodes("/xml/record/datafield");

            if (datas != null && datas.Count > 0)
            {
                for (int i = 0; i < datas.Count; i++)
                {
                    XmlNode xn = datas.Item(i);
                    if (xn.Attributes["tag"] != null)
                    {
                        if (xn.HasChildNodes)
                        {
                            Dictionary<string, string> dc = new Dictionary<string, string>();
                            for (int j = 0; j < xn.ChildNodes.Count; j++)
                            {
                                XmlNode xn1 = xn.ChildNodes[j];
                                if (xn1.Attributes["code"] != null)
                                {
                                    dc.Add(xn1.Attributes["code"].Value, xn1.InnerText);
                                }
                            }
                            if (!Datafield.ContainsKey(xn.Attributes["tag"].Value))
                            {
                                Datafield.Add(xn.Attributes["tag"].Value, dc);
                            }else
                            {
                                List<Dictionary<string, string>> list;
                                if (Datafield[xn.Attributes["tag"].Value].GetType().ToString()== "List")
                                {
                                    list = (List<Dictionary<string, string>>) Datafield[xn.Attributes["tag"].Value];
                                }
                                else
                                {
                                    list = new List<Dictionary<string, string>> { (Dictionary<string, string>)Datafield[xn.Attributes["tag"].Value] };
                                }
                                list.Add(dc);
                            }
                        }

                    }
                }
            }
        }
        public Record()
        {

        }
        public Record(XmlNode xnode)
        {
            XmlNodeList cons = xnode.SelectNodes("controlfield");
            if (cons != null && cons.Count > 0)
            {
                for (int i = 0; i < cons.Count; i++)
                {
                    XmlNode xn = cons.Item(i);
                    if (xn.Attributes["tag"] != null)
                        controlfield.Add(xn.Attributes["tag"].Value, xn.InnerText);
                }
            }
            XmlNodeList datas = xnode.SelectNodes("datafield");

            if (datas != null && datas.Count > 0)
            {
                for (int i = 0; i < datas.Count; i++)
                {
                    XmlNode xn = datas.Item(i);
                    if (xn.Attributes["tag"] != null)
                    {
                        if (xn.HasChildNodes)
                        {
                            Dictionary<string, string> dc = new Dictionary<string, string>();
                            for (int j = 0; j < xn.ChildNodes.Count; j++)
                            {
                                XmlNode xn1 = xn.ChildNodes[j];
                                if (xn1.Attributes["code"] != null)
                                {
                                    if (!dc.ContainsKey(xn1.Attributes["code"].Value))
                                    {
                                        dc.Add(xn1.Attributes["code"].Value, xn1.InnerText);

                                    }else
                                    dc[xn1.Attributes["code"].Value]+= xn1.InnerText;
                                }
                            }
                            if (!datafield.ContainsKey(xn.Attributes["tag"].Value))
                            {
                                datafield.Add(xn.Attributes["tag"].Value, dc);
                            }
                            else
                            {
                                List<Dictionary<string, string>> list;
                                if (datafield[xn.Attributes["tag"].Value].GetType().Name.Contains("List"))
                                {
                                    list = (List<Dictionary<string, string>>)datafield[xn.Attributes["tag"].Value];
                                }
                                else
                                {
                                    list = new List<Dictionary<string, string>> { (Dictionary<string, string>)datafield[xn.Attributes["tag"].Value] };
                                }
                                list.Add(dc);
                                datafield[xn.Attributes["tag"].Value] = list;
                            }
                        }

                    }
                }
            }
        }
        public Dictionary<string, string> Controlfield { get => controlfield; set => controlfield = value; }
        public Dictionary<string, object> Datafield { get => datafield; set => datafield = value; }
    }


    public class RecordList:List<Record> {
        private XmlDocument xdc = new XmlDocument();
       
        public RecordList(string path)
        {
            xdc.Load(path);
            XmlNodeList record = xdc.SelectNodes("/xml/record");
            if (record != null && record.Count > 0)
            {
                for (int i = 0; i < record.Count; i++)
                {
                    XmlNode xn = record.Item(i);
                    this.Add(new Record(xn));
                }
            }
          
        }

    }

    public class DataField
    {
        private Dictionary<string, string> subfield;

        public Dictionary<string, string> Subfield { get => subfield; set => subfield = value; }
    }

    public class CardItem
    {
        private string name;
        private string fontSize="10";
        private string fontFamly="宋体";
        private bool black;
        private bool qiandao;
        private string rowNum;
        private string colNum;
        private string align;
        private string label;
        private string split;

        private float width;
        private float height;
        private float left;
        private float top;
        private bool isHide;
        private string itemContent;
        private string next;
        private string prev;
        private int indent;
        private string datafield;

        private Color color = Color.Black;
        private List<CardItem> childrens = new List<CardItem>();
        private Dictionary<string, string> map;
        public CardItem()
        {

        }
       XmlNode xn;
        public CardItem(XmlNode node)
        {
            initAttr(node);
        }

        public void initAttr(XmlNode node)
        {
            xn = node;
            int out_int = 0;
            if (xn.Attributes == null)
            {
                return;
            }
            if (xn.Attributes["name"] != null)
            {
                name = xn.Attributes["name"].Value;
            }
            if (xn.Attributes["fontSize"] != null)
            {
                fontSize = xn.Attributes["fontSize"].Value;
            }
            if (xn.Attributes["fontFamly"] != null)
            {
                fontFamly = xn.Attributes["fontFamly"].Value;
            }
            if (xn.Attributes["black"] != null)
            {
                black = bool.Parse(xn.Attributes["black"].Value);
            }
            if (xn.Attributes["qiandao"] != null)
            {
                qiandao = bool.Parse(xn.Attributes["qiandao"].Value);
            }

            if (xn.Attributes["align"] != null)
            {
                align = xn.Attributes["align"].Value;
            }
            if (xn.Attributes["label"] != null)
                label = xn.Attributes["label"].Value;
            if (xn.Attributes["width"] != null)
                Width = int.Parse(xn.Attributes["width"].Value);
            if (xn.Attributes["height"] != null)
                height = int.Parse(xn.Attributes["height"].Value);
            if (xn.Attributes["left"] != null)
                left = int.Parse(xn.Attributes["left"].Value);
            if (xn.Attributes["top"] != null)
                top = int.Parse(xn.Attributes["top"].Value);
            if (xn.Attributes["split"] != null)
                split = xn.Attributes["split"].Value;
            if (xn.Attributes["itemContent"] != null)
                itemContent = xn.Attributes["itemContent"].Value;
            if (xn.Attributes["isHide"] != null)
                isHide = bool.Parse(xn.Attributes["isHide"].Value);
            if (xn.Attributes["color"] != null)
                color = System.Drawing.ColorTranslator.FromHtml(xn.Attributes["color"].Value);
            if (xn.Attributes["next"] != null)
                next = xn.Attributes["next"].Value;
            if (xn.Attributes["prev"] != null)
                prev = xn.Attributes["prev"].Value;
            if (xn.Attributes["indent"] != null && int.TryParse(xn.Attributes["indent"].Value, out out_int))
            {
                indent = out_int;

            }
            if (xn.Attributes["datafield"] != null)
                datafield = xn.Attributes["datafield"].Value;
            if (xn.Attributes["map"] != null)
            {
                string[] maps = xn.Attributes["map"].Value.Split(';', ',');
                Dictionary<string, string> hs = new Dictionary<string, string>();
                for (int i = 0; i < maps.Length; i++)
                {
                    string[] hss = maps[i].Split('=');
                    hs.Add(hss[0], hss[1]);
                }
                map = hs;
            }
            if (xn.HasChildNodes)
            {
                for (int i = 0; i < xn.ChildNodes.Count; i++)
                {
                    childrens.Add(new CardItem(xn.ChildNodes[i]));
                }

            }
        }
        public string Name { get => name; set => name = value; }
        public string Label { get => label; set => label = value; }
        public string FontSize { get => fontSize; set => fontSize = xn.Attributes["fontSize"].Value = value; }
        public string FontFamly { get => fontFamly; set => fontFamly = xn.Attributes["fontFamly"].Value = value; }
        public bool Black { get => black; set { black = value; setAttr("black", value); } }
        public bool Qiandao { get => qiandao; set { qiandao = value; setAttr("qiandao", value); } }
        public string RowNum { get => rowNum; set => rowNum = xn.Attributes["rowNum"].Value = value; }
        public string ColNum { get => colNum; set => colNum = xn.Attributes["colNum"].Value = value; }
        public string Align { get => align; set => align = xn.Attributes["align"].Value = value; }
        public float Width
        {
            get => width; set
            {
                width = value; if (xn.SelectSingleNode("@width") != null)
                {
                    xn.Attributes["width"].Value = value.ToString();
                }
                else
                {
                    // 创建节点
                    XmlNode attr = xn.OwnerDocument.CreateNode(XmlNodeType.Attribute, "width", null);
                    attr.Value = value.ToString();
                    // 添加节点属性
                    xn.Attributes.SetNamedItem(attr);
                }
            }
        }
        public float Height { get => height; set { height = value; setAttr("height", value); } }
        public float Left { get => left; set { left = value; setAttr("left", value); } }
        public float Top { get => top; set { top = value; setAttr("top", value); } }

        public List<CardItem> Childrens { get => childrens; set => childrens = value; }
        public Dictionary<string, string> Map { get => map; set => map = value; }
        public string Split { get => split; set { split = value; setAttr("split", value); } }

        public bool IsHide
        {
            get => isHide; set
            {

                isHide = value;

                setAttr("isHide", value);
            }
        }

        public string ItemContent { get => itemContent; set { itemContent = value; setAttr("itemContent", value); } }

        public Color Color
        {
            get => color; set
            {
                color = value;
                setAttr("color", System.Drawing.ColorTranslator.ToHtml(value));
            }
        }

        public string Next
        {
            get => next; set
            {
                next = value;
                setAttr("next",(value));
            }
        }
        public string Prev { get => prev; set
            {
                prev = value;
                setAttr("prev", (value));
            }
        }

        public int Indent { get => indent;set {
                indent = value;
                setAttr("indent", value.ToString());
            }
        }

        public string Datafield { get => datafield; set
            {
                datafield = value;
                setAttr("datafield", value.ToString());
            }
        }

        private void setAttr(string name, object val)
        {
            if (xn.SelectSingleNode("@" + name) != null)
            {
                xn.Attributes[name].Value = val.ToString();
            }
            else
            {
                // 创建节点
                XmlNode attr = xn.OwnerDocument.CreateNode(XmlNodeType.Attribute, name, null);
                attr.Value = val.ToString();
                // 添加节点属性
                xn.Attributes.SetNamedItem(attr);
            }
        }

        public string getValueByKey(string key)
        {
            if (xn.Attributes[key] != null)
            {
                return xn.Attributes[key].Value;
            }
            else
            {
                return "";
            }
        }

        public string getContentByKey(string key)
        {
            if (xn.Attributes[key] != null)
            {
                return xn.Attributes[key].Value;
            }
            else
            {
                return "";
            }
        }
    }

}
